<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp_lib/init.jsp"%>

<script type="text/javascript">
	var edit_form_panel;
	var edit_form_panel_win;

	Ext.onReady(function() {
		edit_form_panel = Ext.create("Ext.form.Panel", {
			url : "edit.htm",
			buttonAlign : "center",
			bodyStyle : "padding: 10px;",
			defaultType : "textfield",
			items : [ {
				fieldLabel : "id",
				name : "role.kid",
				hidden : true
			}, {
				fieldLabel : "角色名 ",
				name : "role.name",
				allowBlank : false
			}, {
				fieldLabel : "权限",
				name : "role.auth_codes",
				hidden : true
			}, {
				xtype : "fieldcontainer",
				fieldLabel : "权限选择",
				layout : "hbox",
				items : [ editTreePanel ]
			} ],
			buttons : [ {
				text : "保存",
				formBind : true, //only enabled once the form is valid
				disabled : true,
				handler : function() {
					var form = this.up("form").getForm();

					//设置选择框
					var auth_codes = treePanel.getLeafIdSelections();

					form.setValues({
						"role.auth_codes" : auth_codes
					});

					if (form.isValid()) {
						form.submit({
							waitMsg : "保存中...",
							success : function(form, action) {
								Ext.Msg.alert("提示", action.result.tip.msg);
								edit_form_panel_win.close();
								dataStore.load();
							},
							failure : function(form, action) {
								Ext.Msg.alert("提示", action.result.tip.msg);
							}
						});
					}
				}
			} ]
		});

		edit_form_panel_win = Ext.create("Ext.Window", {
			title : "角色编辑 ",
			closeAction : "hide",
			items : edit_form_panel
		});
	});

	function myEdit(kid) {
		Ext.Ajax.request({
			url : "${path}/cp/role/role/edit_form.htm?kid=" + kid,
			success : function(response) {
				var json = Ext.util.JSON.decode(response.responseText);
				edit_form_panel.getForm().reset();
				edit_form_panel.getForm().setValues(json);
				//设置树的值
				editTreePanel.setSelections(json["role.auth_codes"]);
				
				edit_form_panel_win.show();
			},
			failure : function(response) {
				Ext.Msg.alert("提示", "操作失败!");
			}
		});
	}//#myEdit
</script>
